package cn.myjerry.others.commons;

import java.util.Queue;

import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.functors.NotNullPredicate;
import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.apache.commons.collections4.queue.PredicatedQueue;
import org.apache.commons.collections4.queue.UnmodifiableQueue;

/**
 * Queue队列
 * 1、循环队列
 *   new CircularFifoQueue(size)
 * 2、只读队列: 不可改变队列
 * 	 UnmodifiableQueue.unmodifiableQueue()
 * 3、断言队列
 *   
 * @author Jerry
 *
 */
public class Demo05 {
	public static void main(String[] args) {
		//circular();
		//readOnly();
		predicate();
	}
	//断言队列
	public static void predicate() {
		CircularFifoQueue<String> que = new CircularFifoQueue<>(2);
		que.add("aaa");
		que.add("bbb");
		que.add("ccc");
		Predicate notNull = NotNullPredicate.INSTANCE;
		Queue<String> que2 = PredicatedQueue.predicatedQueue(que, notNull);
		que2.add(null);
	}
	//只读队列
	public static void readOnly() {
		CircularFifoQueue<String> que = new CircularFifoQueue<>(2);
		que.add("aaa");
		que.add("bbb");
		que.add("ccc");
		Queue<String> readOnlyQue = UnmodifiableQueue.unmodifiableQueue(que);
		readOnlyQue.add("ddd");
	}
	// 循环队列
	public static void circular() {
		CircularFifoQueue<String> que = new CircularFifoQueue<String>(2);
		que.add("aaa");
		que.add("bbb");
		que.add("ccc");
		for(String temp:que) {
			System.out.println(temp);
		}
	}
}
